import java.util.List;

public class Solution {


    public static void main(String[] args) {

        TreeNode node1 = new TreeNode(1);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(3);
        TreeNode node4 = new TreeNode(4);

        List l;
        node1.next = node2;
        node1.random = node3;
        node2.next = node3;
        node2.random = node4;
        node3.next = node4;
        node3.random = node1;
        node4.random = node1;

        TreeNode src = node1;
        TreeNode copy = Clone(src);

        System.out.println(src);
        System.out.println(copy);
    }

    public static TreeNode Clone(TreeNode treeNode) {
        if (treeNode == null) return null;

        TreeNode node = new TreeNode(treeNode.val);
        node.random = treeNode.random;

        node.next = treeNode.next;

        node.next = Clone(treeNode.next);

        return node;
    }
}
class TreeNode {
    int val;
    TreeNode random;
    TreeNode next;

    public TreeNode(int val) {
        this.val = val;
    }
}